<?php

namespace app\index\model;


use think\Model;

class Scene extends Model
{

    public function Pipeline()
    {
        return $this->belongsTo('Pipeline', 'pipeline_id');
    }

    public static function get_scene_id()
    {
        $get_id = Project::get_project_id();
        $get_pip_id=Pipeline::get_pipeline_id($get_id) ;
        $get_sen_id=self::where(['scene_name'=>input('scene_name'),'pipeline_id' =>$get_pip_id['id']])->field('id')->find() ;
        if (isset($get_sen_id['id'])){
            return [1 ,array('scene_id' => $get_sen_id['id'], )];
            }else{
            return [0 , "not found"];
        }  
        // return $result;
    }

    public static function get_sen_id($data){
        return self::where(['scene_name'=>input('scene_name'),'pipeline_id' =>$data['id']])->field('id')->find() ;
    }

    public static function get_data($data='')
    {
        return self::where($data)->select();
    }

    public static function get_count($data='')
    {
        return self::where($data)->count();
    }

    public static function add_data()
    {
        $data_count = self::where(['scene_name'=>input('scene_name'),'pipeline_id'=>input('pipeline_id')])->count() ;
        if(!$data_count){
            $data = input() ;
            return [1 , self::strict(false)->insert($data)];
        }else{
            return [0 , "data is repeat"];
        }
    }

    public static function update_data($data)
    {
        return self::update($data);
    }

     public static function delete_data($data='')
    {
        return self::where($data)->delete();
    }
}